package worldcuptour.activitys;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.LinearLayout.LayoutParams;

public class MainActivity extends Activity {

	Animation animFadeIn;
	Animation animFadeOut1;
	Animation animFadeOut2;
	Button bt;
	final TextView[] tvCidades = new TextView[12];
	boolean firtsCities = true;

	/*
	 * TextView tvBeloHorizonte; TextView tvBrasilia; TextView tvCuiaba;
	 * TextView tvCuritiba; TextView tvManaus; TextView tvNatal; TextView
	 * tvRecife; TextView tvRio; TextView tvSalvador; TextView tvSaoPaulo;
	 * TextView tvPortoAlegre;
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		
		setContentView(R.layout.activity_main);

		tvCidades[0] = (TextView) findViewById(R.id.tvBeloHorizonte);
		tvCidades[1] = (TextView) findViewById(R.id.tvBrasilia);
		tvCidades[2] = (TextView) findViewById(R.id.tvCuiaba);
		tvCidades[3] = (TextView) findViewById(R.id.tvCuritiba);
		tvCidades[4] = (TextView) findViewById(R.id.tvFortaleza);
		tvCidades[5] = (TextView) findViewById(R.id.tvManaus);
		tvCidades[6] = (TextView) findViewById(R.id.tvNatal);
		tvCidades[7] = (TextView) findViewById(R.id.tvRecife);
		tvCidades[8] = (TextView) findViewById(R.id.tvRio);
		tvCidades[9] = (TextView) findViewById(R.id.tvSalvador);
		tvCidades[10] = (TextView) findViewById(R.id.tvSaoPaulo);
		tvCidades[11] = (TextView) findViewById(R.id.tvPortoAlegre);
		bt = (Button) findViewById(R.id.btNext);

		
		animFadeIn = AnimationUtils.loadAnimation(getApplicationContext(),
				R.anim.fade_in);
		animFadeOut1 = AnimationUtils.loadAnimation(getApplicationContext(),
				R.anim.fade_out);
		animFadeOut1.setAnimationListener(animListener1);
		animFadeOut2 = AnimationUtils.loadAnimation(getApplicationContext(),
				R.anim.fade_out);
		animFadeOut2.setAnimationListener(animListener2);
		for (int i = 0; i < 6; i++) {
			tvCidades[i].startAnimation(animFadeIn);
		}

		bt.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (firtsCities == true) {
					for (int i = 0; i < 6; i++) {
						tvCidades[i].startAnimation(animFadeOut1);
						bt.startAnimation(animFadeOut1);
					}
					firtsCities = false;
				} else {
					for (int i = 6; i < 12; i++) {
						tvCidades[i].startAnimation(animFadeOut2);
						bt.startAnimation(animFadeOut2);
					}
					firtsCities = true;
				}
				
			}
		});

		tvCidades[0].setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent i = new Intent(MainActivity.this, FiltrosActivity.class);
				startActivity(i);
				
			}
		});
		
	}

	AnimationListener animListener1 = new AnimationListener() {

		@Override
		public void onAnimationStart(Animation animation) {

		}

		@Override
		public void onAnimationRepeat(Animation animation) {

		}

		@Override
		public void onAnimationEnd(Animation animation) {

			for (int i = 6; i < 12; i++) {
				tvCidades[i].startAnimation(animFadeIn);
			}
			bt.startAnimation(animFadeIn);

		}
	};

	AnimationListener animListener2 = new AnimationListener() {

		@Override
		public void onAnimationStart(Animation animation) {

		}

		@Override
		public void onAnimationRepeat(Animation animation) {

		}

		@Override
		public void onAnimationEnd(Animation animation) {
			for (int i = 0; i < 6; i++) {
				tvCidades[i].startAnimation(animFadeIn);
			}
			bt.startAnimation(animFadeIn);

		}
	};

}
